package com.ssm.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ssm.model.User;
import com.ssm.response.Response;
import com.ssm.response.ResponseCodeEnum;
import com.ssm.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@RestController
@RequestMapping("/User")
public class UserController {

    @Resource
    private IUserService userService;

    @RequestMapping(value= "/showAll",method = RequestMethod.GET)
    public Response selectAll(){
        Response response = new Response();
        ArrayList list = this.userService.selectAll();
        response.success(list);
        return response;
    }
    @RequestMapping(value= "/showUser",method = RequestMethod.GET)
    public Response selectUser(Integer userId){
        Response response = new Response();
        User user = this.userService.selectUser(userId);
        response.success(user);
        return response;
    }

    @RequestMapping(value = "/addUser", method = RequestMethod.POST)
    public Response addUser(User user){
        Response response = new Response();
        Boolean bool = this.userService.addUser(user);
        response.success(bool);
        return response;
    }

    @RequestMapping(value = "/delUser", method = RequestMethod.POST)
    public Response delUser(Integer userId){
        Response response = new Response();
        Boolean bool = this.userService.delUser(userId);
        response.success(bool);
        return response;
    }

    @RequestMapping(value = "/updateUser", method = RequestMethod.POST)
    public Response delUser(User user){
        Response response = new Response();
        Boolean bool = this.userService.updateUser(user);
        response.success(bool);
        return response;
    }
}
